import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'

/** note: submenu only apppear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
//静态路由表
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/authredirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    hidden: true,
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
      }
    ]
  },

  {
    path: '/usermenu',
    component: Layout,
    name: 'Usermenu',
    meta: {
      title: 'user',
      icon: 'example'
    },
    children: [
      {
        path: 'storageusermain',
        name: 'storageuserlist',
        component: () => import('@/views/nested/menu1/menu1-2'),
        meta: { title: 'storageusermain', icon: 'list' },
        children: [
          {
            path: 'list',
            component: () => import('@/views/storageuser/list'),
            name: 'storageuserlist',
            meta: { title: 'storageuserlist', icon: 'list' }
          },{
            path: 'detail',
            component: () => import('@/views/storageuser/detail'),
            name: 'detail',
            meta: {
              title: 'roomuserdetail', icon: 'list', noCache: true, roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },{
            path: 'add',
            component: () => import('@/views/storageuser/create'),
            name: 'StorageuserAdd',
            meta: { title: 'storageuseradd', icon: 'plus' }
          }
        ]
      },
      {
        path: '/customer',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/customer/list',
        name: 'CustomerList',
        meta: {
          title: 'customer',
          icon: 'list'
        },
        children: [
          {
            path: 'list',
            component: () => import('@/views/customer/list'),
            name: 'customerlist',
            meta: { title: 'customerlist', icon: 'list' }
          },
          {
            path: 'detail',
            component: () => import('@/views/customer/detail'),
            name: 'customerdetail',
            meta: {
              title: 'customerdetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'add',
            component: () => import('@/views/customer/create'),
            name: 'customeradd',
            meta: { title: 'customeradd', icon: 'plus' }
          },
          {
            path: 'edit',
            component: () => import('@/views/customer/edit'),
            name: 'customeredit',
            meta: { title: 'customeredit', icon: 'edit' },
            hidden: true
          }
        ]
      },

      // {
      //   path: '/guest',
      //   component: () => import('@/views/nested/menu1/menu1-2'),
      //   redirect: '/guestlist',
      //   name: 'guest',
      //   meta: {
      //     title: 'guest',
      //     icon: 'list'
      //   },children: [
      //     {
      //       path: 'guestlist',
      //       component: () => import('@/views/guest/list'),
      //       name: 'guestlist',
      //       meta: { title: 'guestlist', icon: 'list' },
      //
      //     },
      //     {
      //       path: 'detail',
      //       component: () => import('@/views/guest/detail'),
      //       name: 'detail',
      //       meta: {
      //         title: 'guestdetail', icon: 'list', noCache: true,
      //         roles: ['admin'] // or you can only set roles in sub nav
      //       },
      //       hidden: true
      //     }
      //   ]
      // }
    ]
  },
  {
    path: '/storagemain',
    component: Layout,
    name: 'Storagemain',
    meta: {
      title: 'storagemain',
      icon: 'example'
    },
    children: [
      {
        path: '',
        name: 'storageunit',
        component: () => import('@/views/nested/menu1/menu1-2'),
        meta: {
          title: 'storageunit',
          icon: 'example'
        },
        children: [
          {
            path: 'storageunitadd',
            component: () => import('@/views/storagelist/storageunitadd'),
            name: 'storageunitadd',
            meta: { title: 'storageunitadd', icon: 'list' }
          },
        ]
      },
      {
        path: 'StorageList',
        name: 'StorageList',
        component: () => import('@/views/nested/menu1/menu1-2'),
        meta: {
          title: 'StorageList',
          icon: 'example'
        },
        children: [
          {
            path: 'storagelist',
            component: () => import('@/views/storagelist/list'),
            name: 'Storagelist',
            meta: { title: 'StorageList', icon: 'list' }
          },
          {
            path: 'detail',
            component: () => import('@/views/storagelist/detail'),
            name: 'detail',
            meta: {
              title: 'storagedetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'storageedit',
            component: () => import('@/views/storagelist/edit'),
            name: 'storageedit',
            meta: {
              title: 'storageEit', icon: 'edit', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'storageadd',
            component: () => import('@/views/storagelist/create'),
            name: 'storageadd',
            meta: { title: 'storageadd', icon: 'plus' }
          },
        ]
      },
      {
        path: '/room',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/room/list',
        name: 'roomlist1',
        meta: {
          title: 'roomlist',
          icon: 'example'
        },
        children: [
          {
            path: 'room1',
            component: () => import('@/views/room/list'),
            name: 'roomlist',
            meta: { title: 'roomlist', icon: 'list' }
          },
          {
            path: 'createroom',
            component: () => import('@/views/room/create'),
            name: 'roomcreate',
            meta: { title: 'roomcreate', icon: 'plus' }
          },
          {
            path: 'detail',
            component: () => import('@/views/room/detail'),
            name: 'roomdetail',
            meta: {
              title: 'roomdetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'edit',
            component: () => import('@/views/room/edit'),
            name: 'roomedit',
            meta: { title: 'roomedit', icon: 'list' },
            hidden: true
          },
        ]
      },
    ]
  },
  //nestedRouter,
  {
    path: '/equipment',
    component: Layout,
    name: 'equipment',
    meta: {
      title: 'equipment',
      icon: 'example'
    },
    children: [
      {
        path: '/dtu',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/dtu/list',
        name: 'DtuList1',
        meta: {
          title: 'dtulist',
          icon: 'example'
        },
        children: [
          {
            path: 'dtu',
            component: () => import('@/views/dtu/list'),
            name: 'dtulist',
            meta: { title: 'dtulist', icon: 'list' }
          },
          {
            path: 'detail',
            component: () => import('@/views/dtu/detail'),
            name: 'dtudetail',
            meta: {
              title: 'dtudetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'add',
            component: () => import('@/views/dtu/create'),
            name: 'dtucreate',
            meta: { title: 'dtucreate', icon: 'plus' }
          },
          {
            path: 'edit',
            component: () => import('@/views/dtu/edit'),
            name: 'dtuedit',
            meta: { title: 'dtuedit', icon: 'edit' },
            hidden: true
          }
        ]
      },
      {
        path: '/unit',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/unit/list',
        name: 'UnitList',
        meta: {
          title: 'UnitList',
          icon: 'example'
        },
        children: [
          {
            path: 'list',
            component: () => import('@/views/unit/list'),
            name: 'unitlist',
            meta: { title: 'unitlist', icon: 'list' }
          },
          {
            path: 'create',
            component: () => import('@/views/unit/create'),
            name: 'unitcreate',
            meta: { title: 'unitcreate', icon: 'plus' }
          },
          {
            path: 'detail',
            component: () => import('@/views/unit/detail'),
            name: 'unitdetail',
            meta: {
              title: 'unitdetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'edit',
            component: () => import('@/views/unit/edit'),
            name: 'unitedit',
            meta: { title: 'unitedit', icon: 'list' },
            hidden:true
          },
        ]
      },
      {
        path: '/meter',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/meter/list',
        name: 'MeterList',
        meta: {
          title: 'meter',
          icon: 'example'
        },
        children: [
          {
            path: 'list',
            component: () => import('@/views/meter/list'),
            name: 'meterlist',
            meta: { title: 'meterlist', icon: 'list' }
          },
          {
            path: 'create',
            component: () => import('@/views/meter/create'),
            name: 'metercreate',
            meta: { title: 'metercreate', icon: 'plus' }
          },
          {
            path: 'detail',
            component: () => import('@/views/meter/detail'),
            name: 'meterdetail',
            meta: {
              title: 'meterdetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'edit',
            component: () => import('@/views/meter/edit'),
            name: 'meteredit',
            meta: { title: 'meteredit', icon: 'list' },
            hidden:true
          },
        ]
      },
      {
        path: '/devicedata',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/devicedata/list',
        name: 'devicedata',
        meta: {
          title: 'devicedata',
          icon: 'example'
        },
        children: [
          {
            path: 'list',
            component: () => import('@/views/devicedata/list'),
            name: 'devicedatalist',
            meta: { title: 'devicedatalist', icon: 'list' },
          },
          {
            path: 'detail',
            component: () => import('@/views/devicedata/detail'),
            name: 'devicedatadetail',
            meta: {
              title: 'devicedatadetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'paramlist',
            component: () => import('@/views/devicedata/paramlist'),
            name: 'paramlist',
            meta: { title: 'paramlist', icon: 'list' },
          },
          {
            path: 'paramdetail',
            component: () => import('@/views/devicedata/paramdetail'),
            name: 'paramdetail',
            meta: {
              title: 'paramdetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'messagelist',
            component: () => import('@/views/devicedata/messagelist'),
            name: 'messagelist',
            meta: { title: 'messagelist', icon: 'list' }
          },
          {
            path: 'messagedetail',
            component: () => import('@/views/devicedata/messagedetail'),
            name: 'messagedetail',
            meta: {
              title: 'messagedetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },{
            path: 'devicedatahistory',
            component: () => import('@/views/devicedata/devicedatahistory'),
            name: 'devicedatahistory',
            meta: { title: 'devicedatahistory', icon: 'list' }
          },{
            path: 'devicedatadown',
            component: () => import('@/views/devicedata/devicedatadown'),
            name: 'devicedatadown',
            meta: { title: 'devicedatadown', icon: 'list' },
            hidden: true
          },{
            path: 'noticelist',
            component: () => import('@/views/devicedata/noticelist'),
            name: 'noticelist',
            meta: { title: 'noticelist', icon: 'list' }
          },{
            path: 'noticedetail',
            component: () => import('@/views/devicedata/noticedetail'),
            name: 'noticelist',
            meta: { title: 'noticedetail', icon: 'list' },
            hidden: true
          }

        ]
      }
    ]
  },
  {
    path: '/Operation',
    component: Layout,
    name: 'Operation',
    meta: {
      title: 'Operation',
      icon: 'example'
    },
    children: [
      {
        path: '/operation',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/operation/list',
        name: 'OperationList1',
        meta: {
          title: 'operationlist',
          icon: 'example'
        },
        children: [
          {
            path: 'list',
            component: () => import('@/views/Operation/list'),
            name: 'OperationMaintenanceMonitoring',
            meta: { title: 'OperationMaintenanceMonitoring', icon: 'list' }
          },
          {
            path: 'detail',
            component: () => import('@/views/Operation/detail'),
            name: 'Operationdetail',
            meta: {
              title: 'Operationdetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'edit',
            component: () => import('@/views/Operation/edit'),
            name: 'Operationedit',
            meta: { title: 'Operationedit', icon: 'list' },
            hidden:true
          },
        ]
      },
    ]
  }

]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

//需要根据不同角色进行动态挂载的路由
export const asyncRouterMap = [

  {
    path: '/system',
    component: Layout,
    name: 'system',
    meta: {
      title: 'system',
      icon: 'example'
    },
    children: [{
        path: '',
        component: ()=> import('@/views/nested/menu1/menu1-2'),
        redirect: '/faultcode/list',
        name: 'faultcode',
        meta: {
          title: 'faultcode',
          icon: 'example'
        },
        children: [
          {
            path: 'faultcodelist',
            component: () => import('@/views/faultcode/list'),
            name: 'faultcodelist',
            meta: { title: 'faultcodelist', icon: 'list' }
          },
          {
            path: 'create',
            component: () => import('@/views/faultcode/create'),
            name: 'faultcodecreate',
            meta: {
              title: 'faultcodecreate', icon: 'plus', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
          },
          {
            path: 'detail',
            component: () => import('@/views/faultcode/detail'),
            name: 'faultcodedetail',
            meta: {
              title: 'faultcodedetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          }
        ]
    },
      {
        path: '/admin',
        component: () => import('@/views/nested/menu1/menu1-2'),
        redirect: '/adminlist',
        name: 'admin',
        meta: {
          title: 'admin',
          icon: 'list'
        },children: [
          {
            path: 'adminlist',
            component: () => import('@/views/admin/list'),
            name: 'adminlist',
            meta: { title: 'adminlist', icon: 'list' },

          },
          {
            path: 'admincreate',
            component: () => import('@/views/admin/create'),
            name: 'admincreate',
            meta: {
              title: 'admincreate', icon: 'plus', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
          },
          {
            path: 'detail',
            component: () => import('@/views/admin/detail'),
            name: 'detail',
            meta: {
              title: 'admindetail', icon: 'list', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          },
          {
            path: 'adminedit',
            component: () => import('@/views/admin/edit'),
            name: 'edit',
            meta: {
              title: 'adminedit', icon: 'edit', noCache: true,
              roles: ['admin'] // or you can only set roles in sub nav
            },
            hidden: true
          }
        ]
      },]
  },
  { path: '*', redirect: '/404'}
]
